<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui">

<ui:composition template="../_template.xhtml">
	<ui:define name="title">
		Consulta de Alertas - Ctrl.Liberty
	</ui:define>
	
	<ui:define name="content">
		<h:form>
			<h2>Alertas</h2>
			
			<div> 
				<h:panelGrid columns="3">
					<h:panelGroup>
						<h:outputLabel value="Telefone Principal" >*:</h:outputLabel>
						<h:selectOneMenu value="#{alertaBean.idTelefone}" style="width:145px" onchange="submit();" valueChangeListener="#{alertaBean.listarAlertas}">
							<f:selectItems var="tel" itemValue="#{tel.id}" itemLabel="#{tel.numero}" value="#{alertaBean.listaTelefone}" />
						</h:selectOneMenu>		
					</h:panelGroup>
				</h:panelGrid>
			</div>
			
			<div style="padding-bottom: 15px">
				<p:fieldset legend="Inserir Alerta" toggleable="true" collapsed="true">
					<div>
						<div style="float:left;">
							<h:panelGrid columns="2" >
								
								<h:panelGroup>
									<h:outputLabel value="Tipo de Alerta" >*: </h:outputLabel>
									<h:selectOneMenu value="#{alertaBean.alerta.tipoAlerta}"  valueChangeListener="#{alertaBean.alterarTipoLimite}" style="width:155px">
										<f:ajax event="change" execute="@this" listener="#{alertaBean.alterarTipoLimite}" render="tipoLimite"/>
										<f:selectItem itemValue="" itemLabel="Selecione..."/>
										<f:selectItem itemValue="LIGACAO" itemLabel="Ligação"/>
										<f:selectItem itemValue="MENSAGEM" itemLabel="Mensagem"/>
										<f:selectItem itemValue="INTERNET" itemLabel="Internet"/>
									</h:selectOneMenu>
								</h:panelGroup>
								
								<h:panelGroup>
									<h:outputLabel value="Limite">*: </h:outputLabel>
									<p:spinner value="#{alertaBean.alerta.valorLimite}" min="1" max="99999" />
									<h:outputText id="tipoLimite" value="#{alertaBean.alerta.tipoLimite}" style="padding-left:5px"/>
								</h:panelGroup>
								
								<h:panelGroup>
									<h:outputLabel value="Data Inicial">*:</h:outputLabel>
									<p:calendar value="#{alertaBean.alerta.dataLimiteInicial}">
										<f:converter converterId="dateConverter"/>
									</p:calendar>
								</h:panelGroup>
								
								<h:panelGroup>
									<h:outputLabel value="Data Final">*:</h:outputLabel>
									<p:calendar value="#{alertaBean.alerta.dataLimiteFinal}">
										<f:converter converterId="dateConverter"/>
									</p:calendar>
								</h:panelGroup>
							</h:panelGrid>
						</div>
						<div style="float:right;">
			            	<p:commandButton action="#{alertaBean.cadastrarAlerta}" value="incluir" update="@form"/>
			            </div> 
					</div>
				</p:fieldset>
			</div>
			
			<div id="resultadoPesquisa">
				<p:fieldset legend="Resultado da Pesquisa" rendered="#{not empty alertaBean.listaAlerta}">
					<p:dataTable id="alertas" var="alerta" value="#{alertaBean.listaAlerta}" paginator="true" rows="10"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="10">
	
						<f:facet name="header">Alertas</f:facet>
	
						<p:column>
							<f:facet name="header">
								<h:outputText value="Tipo Alerta" />
							</f:facet>
							<h:outputText value="#{alerta.tipoAlerta}" />
						</p:column>
	
						<p:column>
							<f:facet name="header">
								<h:outputText value="Limite" />
							</f:facet>
							<h:outputText value="#{alerta.valorLimite} - #{alerta.tipoLimite}" />
						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="Data Inicial" />
							</f:facet>
							<h:outputText value="#{alerta.dataLimiteInicial}" >
								<f:converter converterId="dateConverter"/>
							</h:outputText>
						</p:column>
	
						<p:column>
							<f:facet name="header">
								<h:outputText value="Data Final" />
							</f:facet>
							<h:outputText value="#{alerta.dataLimiteFinal}">
								<f:converter converterId="dateConverter"/>
							</h:outputText>
							
						</p:column>
	
						<p:column>
							<f:facet name="header">
								<h:outputText value="Ativado" />
							</f:facet>
							<h:outputText value="#{alerta.alertaAcionadoFormatado}"/>
							
						</p:column>
						<p:column style="width:20px;">
							
							<p:commandButton image="ui-icon ui-icon-trash" action="#{alertaBean.removerAlerta}" update="@form">
								<f:setPropertyActionListener target="#{alertaBean.alerta}" value="#{alerta}" />
							</p:commandButton>
						</p:column>
	
					</p:dataTable>
				</p:fieldset>
			</div>
		</h:form>
		
	</ui:define>
	
</ui:composition>
</html>